package turrets;
import info.gridworld.actor.Actor;
import java.util.ArrayList;

import Enemies.Enemy;
import Manage.Counter;
public class Cannon extends Turret{
	private static int price = 960;
	public Cannon(){
		super();
		price = 960;
		upgradeprice = price / 4;
		sellprice = price / 2;
		setValues(30,1,1);
		Counter.addMoney(-1*(getPrice() - super.getPrice()));
	}
	public void playSound(){
		new AePlayWave("CannonShot.wav").start();
	}
	public int getPrice(){
		return price;
	}
	public void attack(Enemy enemy){
		if(enemy!=null){
			
			setDirection(getLocation().getDirectionToward(enemy.getLocation()));
			enemy.takeDamage(damage);
			splashDamage(enemy);
			playSound();
		}
		else
			cooldown++;
		}
	public String getUpGradeInfo(){
		String s = "Upgrade Number       % increase        Total damage     Price\n" + 
				   "Base                                 0%                      30                     960\n" + 
				   "1st                                  15%                      34                     240\n" +
				   "2nd                                  30%                     44                     480\n" +
				   "3rd                                  45%                      63                     720";
		return s;
	}
	public void splashDamage(Enemy enemy){
		ArrayList<Actor> enemies= new ArrayList<Actor>();
		enemies = getGrid().getNeighbors(enemy.getLocation());
		ArrayList<Enemy> enemie= new ArrayList<Enemy>();
		for(int i = 0; i < enemies.size(); i++){
			if(enemies.get(i) instanceof Enemy)
				enemie.add((Enemy) enemies.get(i));
		}
		for(int i = 0; i < enemie.size(); i++){
			enemie.get(i).takeDamage(damage/10);
		}
	}
}
